﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Istace.Framework.Mapping.Core;

namespace Istace.Framework.Mapping.TestConsole
{
    static class Program
    {
        static void Main()
        {
            // Initialize the mappers with the given assemblies in the app.config
            // They will be inspected and their dependencies too. (configurable)
            Mapper.Initialize(typeof(Program).Assembly, true, true);

            // Add object to a string repository
            Repository.AddInstance("string", "string", true);
            Repository.AddInstance("string2", "string2", true);
            Repository.AddInstance("string", "string3", true);

            // Add object to an integer repository
            Repository.AddInstance("string", 20);
            Repository.AddInstance("test", 10);
            
            // Display the indexed value from a repository
            Console.WriteLine("Display the string referenced with 'string' index : {0}",    Repository.GetInstance<string>("string"));
            Console.WriteLine("Display integer referenced with 'string' index : {0}",       Repository.GetInstance<int>("string"));
            Console.WriteLine("Display integer referenced with 'test' index : {0}",         Repository.GetInstance<int>("test"));

            // Test some basic mapping features
            Console.WriteLine("\nCall Map<int, string> method : {0}",   Mapper.Map<int, string>(10));
            Console.WriteLine("Call Map<string, int> method : {0}",     Mapper.Map<string, int>("456"));
            Console.WriteLine("Call Map<int> method : {0}",             Mapper.Map<int>("456"));
            Console.WriteLine("Call Map<A, string> method : {0}",       Mapper.Map<A, string>(new A { Foo = "Foo text" }));

            // A little demo with list
            Console.WriteLine("\nConvert a list of string to integer with MapList<string, int> \n{0}",  String.Join(Environment.NewLine, Mapper.MapList<int>(new List<string> { "0", "1", "2", "3" }).ToList()));
            Console.WriteLine("\nConvert a list of A to string with MapList<string> \n{0}",             String.Join(Environment.NewLine, Mapper.MapList<string>(new List<A> { new A { Foo = "First" }, new A { Foo = "Second" } })));

            Console.ReadKey();           
        }
    }
}
